# 作业一：将之前封装的`MyMath`类中的实例方法改为静态方法, 体会两者的区别.


class MyMath:
    @staticmethod
    def add(x, y):
        return x + y

    @staticmethod
    def min(x, y):
        return x - y

    @staticmethod
    def mul(x, y):
        return x * y

    @staticmethod
    def div(x, y):
        return x / y

    @staticmethod
    def pow(x, y):
        return x ** y

    @staticmethod
    def root(x, y):
        return x ** (1/y)


print(MyMath.add(2, 3))
print(MyMath.min(2, 3))
print(MyMath.mul(2, 3))
print(MyMath.div(2, 3))
print(MyMath.pow(2, 3))
print(MyMath.root(2, 3))

#作业二：为上节课自定义类添加以下功能：
# - 添加类属性
# - 添加类私有属性
# - 添加类方法或者类的私有属性
# - 在`__init__`方法中初始化实例属性
# - 在`__init__`方法中绑定私有实例属性
# - 在自定义类中实现`__str__`, 自定义输出格式


class Phone(object):
    price = 5000

    # 添加类属性
    ScreenType = "全面屏"

    # 添加类私有属性
    __ScreenSize = 5.5

    # 获取私有属性
    @classmethod
    def get_ScreenSize(cls):
        return cls.__ScreenSize


screen = Phone()

print("打印phone的屏幕类型的类属性，ScreenType：", Phone.ScreenType)
print("打印phone的私有属性，屏幕尺寸，ScreenSize：", Phone._Phone__ScreenSize)
print("获取私有属性：", screen.get_ScreenSize())


class Android(Phone):
    syste = "ANDR"
    brand = '小米'
    color = 'Black'
    telephone = True

    # 添加类方法或者类的私有属性
    @classmethod
    def __new__(cls, *args, **kwargs):
        print("添加的类方法")
        return super().__new__(cls)


oppo = Android()
print(oppo.telephone)

# 在__init__中初始化实例属性


class ChinesePhone(Phone):
    nation = "cn"

    def __init__(self, rank):
        self.__rank = rank


xiaomi = ChinesePhone(2)

print("实例属性中的私有属性(小米排名)：", xiaomi._ChinesePhone__rank)


class Iphone(Phone):
    syste = "IOS"
    brand = '苹果'
    color = 'white'


# 实例化
print("售价5000的苹果：", Iphone.price)
print("售价5000的Android：", Android.price)
print("将打印Iphone的品牌：", Iphone.brand)


# 在自定义类中实现`__str__`, 自定义输出格式

class MyDict(dict):
    def __iadd__(self, other):
        self.update(other)
        return self

    def __str__(self):
        return f"My Dict {self.items()}"


a = MyDict(a=1, b=2)
b = MyDict(c=3, d=4)
print(a)
print(b)

a += b
print(a)